package jp.co.itfrontier.mashup.core {
	import flash.utils.Dictionary;
	import jp.co.itfrontier.mashup.command.ICommand;
	import flash.events.EventDispatcher;
	
	public class EventController {
		
		private static var dispacher:EventDispatcher = new EventDispatcher();

		private static var funcDictionary:Dictionary = new Dictionary(true);

		public static function getInstance():EventDispatcher {
			return dispacher;
		}

		public static function addCommand(eventName:String, clazz:Class):void {
			var command:ICommand = new clazz();
			dispacher.addEventListener(eventName, command.execute);
			funcDictionary[eventName] = command;

		}
		
		public static function removeCommand(eventName:String):void {
			dispacher.removeEventListener(eventName, (funcDictionary[eventName] as ICommand).execute);

			var c:ICommand = funcDictionary[eventName] as ICommand;
			c = null;
			funcDictionary[eventName] = null;

		}
		
		public static function dispathEvent(event:*):void {
			dispacher.dispatchEvent(event);
		}
	}
}